/**
 * @file TestHelpers.cs
 * @author Zane Mayo
 * @date 15/5/2009
 */

using System;
using System.Threading;
using NUnit.Framework;

using MxitAPI;

namespace MxitAPITest {
	
	
	[ TestFixture ]
	public class TestHelpers {
		
		static int threadNumber = 0;
		
		[ Test ]
		public void TestCase() {
		}
		
		public static void SetupServerInfo() {
			/*Connection connection = Connection.Instance;
			HttpServerInfo serverInfo = new HttpServerInfo();
			serverInfo.Address = "http://int.poll.mxit.com:80/mxit/ZA?";
			serverInfo.Timeout = 20000;
			connection.PrimaryServer = serverInfo;
			connection.MessageTranceiver = new HttpMessageTransceiver();*/
			
			
			Connection connection = Connection.Instance;
			connection.Password = "ODQL7IQyO2Uag0WV3Ec60g==";
			TcpServerInfo serverInfo = new TcpServerInfo();
			serverInfo.Address = "41.191.124.10";
			serverInfo.Port = 9119;
			serverInfo.Timeout = 20000;
			connection.PrimaryServer = serverInfo;
			connection.LoginName = "278444435510";
			connection.MessageTranceiver = new TcpMessageTransceiver();
			
			SendQueueWorker sendQueueWorker = new SendQueueWorker( ProtocolMessageSendQueue.Instance, connection.MessageTranceiver );
			Thread t = new Thread( new ThreadStart( sendQueueWorker.SendProtocolMessages ) );
			
			t.Name = "SendQueueWorkerThread" + threadNumber++;
			t.Start();
			
		}
		
		public static void Login() {
			
			Connection connection = Connection.Instance;
			/*HttpServerInfo serverInfo = new HttpServerInfo();
			serverInfo.Address = "http://int.poll.mxit.com:80/mxit/ZA?";
			serverInfo.Timeout = 20000;
			connection.PrimaryServer = serverInfo;*/
			if ( connection.PrimaryServer == null )
				TestHelpers.SetupServerInfo();
			
			Handler loginHandler = new LoginHandler( "278444435510", "19851985" ); //"ODQL7IQyO2Uag0WV3Ec60g==" );
			//connection.MessageTranceiver = new HttpMessageTransceiver();
			
			loginHandler.Execute();
			
		/*	Assert.AreEqual( ConnectionStatus.Connected, Connection.Instance.ConnectionStatus );
			Assert.AreEqual( "27844443551", connection.UserName );
			Assert.AreEqual( "ODQL7IQyO2Uag0WV3Ec60g==", connection.Password );
			TimeSpan ts = (DateTime.UtcNow - new DateTime(1970,1,1,0,0,0));
			Assert.IsTrue( connection.LoginDate - ts.TotalSeconds < 10);
			Assert.AreEqual( "", connection.CurrentUrl  );
			Assert.AreEqual( 60, ApplicationInfo.Instance.MaxSupportedVersion );*/
		}
		
		
	}
}
